import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class VerifierService extends BaseService<any> {
  private readonly logger = new Logger(VerifierService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getPage
   * 对应 PHP: VerifierService_admin::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(where: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: $search_model = $this->model->where([ ['site_id', '=', $this->site_id] ])->with(['member' => function($query){             $query->field('member_id, n...
const search_model = this.model.where([ ['site_id', '=', this.site_id) )).with([member: function(query){
            query.field('member_id, nickname, mobile, headimg');
  }

  /**
   * getList
   * 对应 PHP: VerifierService_admin::getList()
   * 逻辑类型: undefined - undefined
   */
  async getList(where: any[]) {
    // 基于PHP真实逻辑: getList
    // PHP原文: return $this->model->where([['site_id', '=', $this->site_id]])->with(['member' => function ($query) {             $query->field('member_id, nickname, ...
return this.model.where([['site_id', '=', this.site_id))).with([member: function (query) {
            query.field('member_id, nickname, mobile, headimg');
  }

  /**
   * makeUp
   * 对应 PHP: VerifierService_admin::makeUp()
   * 逻辑类型: undefined - undefined
   */
  async makeUp(data: any) {
    // 基于PHP真实逻辑: makeUp
    // PHP原文: //核销类型         if(!empty($data['verify_type'])){             $type = VerifyDict::getType();             $type_array = [];             foreach ($data['...
//核销类型
        if(!!data.verify_type)){
            const type = VerifyDict.getType(];
            const type_ = [);
            foreach (data.verify_type as key => value) {
                if (array_key_exists(value, type)) {
                    type_array[key].verify_type = value;
                    type_array[key].verify_type_name = type[value].name;
                }
            }
            data.verify_type_array = type_array;
  }

  /**
   * getDetail
   * 对应 PHP: VerifierService_admin::getDetail()
   * 逻辑类型: undefined - undefined
   */
  async getDetail(id: any) {
    // 基于PHP真实逻辑: getDetail
    // PHP原文: return $this->model->with(['member' => function($query){             $query->field('member_id, nickname, mobile, headimg');...
return this.model.with([member: function(query){
            query.field('member_id, nickname, mobile, headimg');
  }

  /**
   * add
   * 对应 PHP: VerifierService_admin::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $member = (new Member())->where([ ['site_id', '=', $this->site_id], ['member_id', '=', $data['member_id'] ] ])->findOrEmpty();         if ($member->is...
const member = this.memberService.where([ ['site_id', '=', this.site_id], ['member_id', '=', data.member_id ) )).findOrEmpty(];
        if (member.isEmpty()) throw new BusinessException('MEMBER_NOT_EXIST'];

        const model = this.model.where([ ['site_id', '=', this.site_id], ['member_id', '=', data.member_id ) )).findOrEmpty(];
        if (!model.isEmpty()) throw new BusinessException('VERIFIER_EXIST'];

        data.create_time = time(];
        data.site_id = this.site_id;
        const res = this.model.create(data);
        return res.id;
    }

    /**
     * 编辑核销员
     * @param data
     * @return void
     */
    async edit(id, data)
    {
        this.model.where([ ['site_id', '=', this.site_id], ['id', '=',id) )).update(data);
    }

    /**
     * 删除核销员
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        const res = this.model.where([['id', '=', id], ['site_id', '=', this.site_id))).delete(];
        return res;
    }
}
  }

  /**
   * edit
   * 对应 PHP: VerifierService_admin::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(id: any, data: any) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $this->model->where([ ['site_id', '=', $this->site_id], ['id', '=',$id] ])->update($data);     }      /**      * 删除核销员      * @param int $id      * @r...
this.model.where([ ['site_id', '=', this.site_id], ['id', '=',id) )).update(data);
    }

    /**
     * 删除核销员
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        const res = this.model.where([['id', '=', id], ['site_id', '=', this.site_id))).delete(];
        return res;
    }
}
  }

  /**
   * del
   * 对应 PHP: VerifierService_admin::del()
   * 逻辑类型: undefined - undefined
   */
  async del(id: number) {
    // 基于PHP真实逻辑: del
    // PHP原文: $res = $this->model->where([['id', '=', $id], ['site_id', '=', $this->site_id]])->delete();         return $res;     } }...
const res = this.model.where([['id', '=', id], ['site_id', '=', this.site_id))).delete(];
        return res;
    }
}
  }
}
